package com.cat.dataStructure;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/special-array-ii/description/
 * @create 2025/8/16 09:08
 * @since JDK17
 */

public class Solution22 {
    int get(int a, int b) {
        return Math.abs(a % 2 - b % 2);
    }
    public boolean[] isArraySpecial(int[] nums, int[][] queries) {
        int n = nums.length, m = queries.length;
        int[] prefix = new int[n];
        boolean[] ans = new boolean[m];
        for (int i = 0; i < n - 1; i++) {
            prefix[i + 1] = prefix[i] + get(nums[i], nums[i + 1]);
        }
        for (int i = 0, a, b; i < m; i++) {
            a = queries[i][0];
            b = queries[i][1];
            ans[i] = prefix[b] - prefix[a] == b - a;
        }
        return ans;
    }
}
